//
//  LimitCell.swift
//  XiaoXiangMu1604
//
//  Created by qianfeng on 16/9/26.
//  Copyright © 2016年 SunPiaoLiang. All rights reserved.
//

import UIKit

class ReduceCell: UITableViewCell {

    @IBOutlet weak var bgImageView: UIImageView!
    
    @IBOutlet weak var appImageView: UIImageView!
   
    @IBOutlet weak var priceLabel: UILabel!
    
    @IBOutlet weak var oldPriceLabel: UILabel!
    
    @IBOutlet weak var myStarView: StarView!
    
    @IBOutlet weak var categoryLabel: UILabel!
    
    @IBOutlet weak var shareLabel: UILabel!
    
    @IBOutlet weak var favoriteLabel: UILabel!
    
    @IBOutlet weak var downloadLabel: UILabel!
    
    @IBOutlet weak var titleLabel: UILabel!
    
    //价格的横线
    private var lineView:UIView?
    
    //显示数据
    func config(model:LimitModel,atIndex index:Int){
        
        //1.背景图片
        if index % 2 == 0{
            
            bgImageView.image = UIImage(named: "cate_list_bg1")
            
        }else{
            
            bgImageView.image = UIImage(named: "cate_list_bg2")
        }
        
        //2.应用的图片，在线请求图片
        let url = NSURL(string: model.iconUrl!)
        
        appImageView.layer.cornerRadius = 10
        
        appImageView.clipsToBounds = true
        
        //使用第三方库Kingfisher来下载图片
        appImageView.kf_setImageWithURL(url!)
        
        //3.名字
        titleLabel.text = "\(index)" + model.name!
        
        //4.现价
        priceLabel.text = "现价" + (model.currentPrice!)
        
        //5.原价
        let priceStr = "$:" + model.lastPrice!
        
        
        
        let attrStr = NSAttributedString(string: priceStr, attributes: [NSStrikethroughStyleAttributeName:NSNumber(int: 1),NSStrikethroughColorAttributeName:UIColor.redColor()])
        
        oldPriceLabel.attributedText = attrStr
//        
//        //横线
//        if lineView == nil{
//            
//            lineView = UIView(frame: CGRectMake(0,10,60,1))
//            
//            lineView!.backgroundColor = UIColor.blackColor()
//            
//            oldPriceLabel.addSubview(lineView!)
//            
//        }
        
        //6.星级
        myStarView.setRating(model.starCurrent!)
        
        //7.类型
        categoryLabel.text = MyUtil.transferCateName( model.categoryName!)
        
        //8.分享  收藏  下载
        shareLabel.text = "分享:" + model.shares! + "次"
        
        favoriteLabel.text = "收藏" + model.favorites! + "次"
        
        downloadLabel.text = "下载" + model.downloads! + "次"
        
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
